package com.miles.controller;


import com.miles.dto.Company;
import com.miles.service.ICompany;
import com.miles.service.impl.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
@Controller
@RequestMapping("/data")
@ResponseBody
public class DemoComtroller {
    @Autowired
    private ICompany companyService;

    @RequestMapping("/queryCompany")
    public List<Company> queryCompany(Company company)
    {
        if(company != null){
        if(company.getUser() != null)
            company.setUser("".equals(company.getUser().trim())?null:company.getUser());
        if(company.getCompany() != null)
            company.setCompany("".equals(company.getCompany().trim())?null:company.getCompany());
        }else{
            company = new Company();
        }
        return companyService.queryCompany(company);
    }

    @RequestMapping("/add")
    public List<Company> addCompany(Company company)
    {
        if(company != null){
            if(company.getUser() != null && !"".equals(company.getUser().trim()) &&
                    company.getCompany() != null && !"".equals(company.getCompany().trim())){
                companyService.addCompany(company);
            }
        }
        return companyService.queryCompany(new Company());
    }
}
